// pages/orderDetails/orderDetails.js
import util from "../../utils/util.js";
Page({
  /**
   * 页面的初始数据
   */
  data: {
    state: ""
  },
  //生命周期函数--监听页面加载
  onLoad: function(options) {
    // this.detailCon()
    this.detailCon(options.id);
  },
  //详情
  detailCon(id) {
    const url = util.api.detail + id;
    const data = {
      token: util.token
    };
    const method = "GET";
    util.sendRequest(url, method, data).then(res => {
      if (!res.errorCode) {
        this.setData({
          ...res.data
        });
        this._state(res.data);
      }
      console.log(res);
    });

  },
  _state(item) {
    const payTime = item.pay_time_text; //支付时间
    const refundTime = item.refund_time_text; //退款时间
    const expiredTime = item.expired_time_text; //过期时间
    //交易成功
    payTime && this._stateTxt("交易成功");
    //交易关闭
    expiredTime && this._stateTxt("交易关闭");
    //已退款
    refundTime && this._stateTxt("已退款");
    //待支付
    !payTime && !expiredTime && this._stateTxt("待支付");
  },
  //stateTxt
  _stateTxt(txt) {
    this.setData({
      state: txt
    });
  },
  // 分享
  onShareAppMessage() {}
});
